package com.cw.jeeyt.service.impl.system;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cw.jeeyt.common.utils.StringUtils;
import com.cw.jeeyt.service.bo.system.SystemTemplateModuleInfoBo;
import com.cw.jeeyt.dao.intf.system.SystemTemplateModuleInfoDao;
import com.cw.jeeyt.dao.model.system.SystemTemplateModuleInfoDo;
import com.cw.jeeyt.service.converter.system.SystemTemplateModuleInfoConverter;
import com.cw.jeeyt.service.intf.system.SystemTemplateModuleInfoService;
import com.cw.lang.mybatis.dto.PageInfo;
import com.cw.lang.common.utils.SequenceTool;

/**
 * 生成代码模板模块信息业务实现类
 *
 * @author chenw
 * @version 1.0.0
 */
@Service
public class SystemTemplateModuleInfoServiceImpl implements SystemTemplateModuleInfoService {

    private static final Logger logger = LoggerFactory.getLogger(SystemTemplateModuleInfoServiceImpl.class);
    @Autowired
    private SystemTemplateModuleInfoDao systemTemplateModuleInfoDao;//生成代码模板模块信息数据库操作接口

    /**
     * 分页查询生成代码模板模块信息
     *
     * @param systemTemplateModuleInfoBo
     * @param startNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @Override
    public PageInfo<SystemTemplateModuleInfoBo> queryByPage(SystemTemplateModuleInfoBo systemTemplateModuleInfoBo,
        Integer startNum, Integer pageSize) throws Exception {
        PageInfo<SystemTemplateModuleInfoDo> pageInfo = systemTemplateModuleInfoDao.queryByPage(
            SystemTemplateModuleInfoConverter.bo2Do(systemTemplateModuleInfoBo), startNum, pageSize);
        return new PageInfo<>(pageInfo, SystemTemplateModuleInfoConverter.doList2BoList(pageInfo.getList()));
    }

    /**
     * 根据主键查寻生成代码模板模块信息
     *
     * @param id
     * @return
     */
    @Override
    public SystemTemplateModuleInfoBo getSystemTemplateModuleInfoById(String id) throws Exception {

        if (StringUtils.isEmpty(id)) {
            logger.error("--主键id为空--");
            return null;
        }
        return SystemTemplateModuleInfoConverter.do2Bo(systemTemplateModuleInfoDao.getById(id));
    }

    /**
     * 根据模板id查询模板模块信息
     *
     * @param templateId 模板模块id
     * @return
     * @throws Exception
     */
    @Override
    public List<SystemTemplateModuleInfoBo> queryListByTemplateId(String templateId) throws Exception {

        if (StringUtils.isEmpty(templateId)) {
            logger.error("生成代码模板模块信息id为空");
            return null;
        }

        return SystemTemplateModuleInfoConverter.doList2BoList(
            systemTemplateModuleInfoDao.queryListByTemplateId(templateId));
    }

    /**
     * 新增生成代码模板模块信息
     *
     * @param systemTemplateModuleInfoBo
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer insert(SystemTemplateModuleInfoBo systemTemplateModuleInfoBo) throws Exception {

        if (systemTemplateModuleInfoBo == null) {
            logger.error("生成代码模板模块信息为空");
            return null;
        }
        SystemTemplateModuleInfoDo systemTemplateModuleInfo = SystemTemplateModuleInfoConverter.bo2Do(
            systemTemplateModuleInfoBo);
        systemTemplateModuleInfo.setId(SequenceTool.nextId());
        return systemTemplateModuleInfoDao.insert(systemTemplateModuleInfo);
    }

    /**
     * 更新生成代码模板模块信息
     *
     * @param systemTemplateModuleInfoBo
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void update(SystemTemplateModuleInfoBo systemTemplateModuleInfoBo) throws Exception {

        if (systemTemplateModuleInfoBo == null) {
            logger.error("生成代码模板模块信息为空");
            return;
        }
        systemTemplateModuleInfoDao.update(SystemTemplateModuleInfoConverter.bo2Do(systemTemplateModuleInfoBo));
    }

    /**
     * 删除生成代码模板模块信息
     *
     * @param systemTemplateModuleInfoBo
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delete(SystemTemplateModuleInfoBo systemTemplateModuleInfoBo) throws Exception {

        if (systemTemplateModuleInfoBo == null) {
            logger.error("生成代码模板模块信息为空");
            return;
        }
        systemTemplateModuleInfoDao.delete(SystemTemplateModuleInfoConverter.bo2Do(systemTemplateModuleInfoBo));
    }
}
